package SwordFingerOffer;

public class Q25_MergeList {


    //合并两个有序链表 递增
    //双指针
    //链表coding无小事
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        if (l1 == null && l2 == null){
            return null;
        }
        //头
        ListNode ans = new ListNode(0);
        ListNode res = ans;

        while (l1 != null && l2 != null){
            if (l1.val <= l2.val){
                ans.next = l1;
                l1 = l1.next;
            }else {
                // >
                ans.next = l2;
                l2 = l2.next;
            }
            ans = ans.next;
        }

        //长短要统一
        if (l1 != null){
            ans.next = l1;
        }

        if (l2 != null){
            ans.next = l2;
        }

        return res.next;
    }

}
